fix(otelaws): don't record 304 Not Modified as a span error - #9474
fix(otelaws): don't record 304 Not Modified as a span error#9474pujitha24 wants to merge 4 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9474 +/- ##
=======================================
- Coverage 84.5% 84.5% -0.1%
=======================================
Files 203 203
Lines 16805 16813 +8
=======================================
- Hits 14215 14212 -3
- Misses 2110 2121 +11
Partials 480 480
🚀 New features to boost your workflow:
|
ps-mir
left a comment
There was a problem hiding this comment.
A comment regarding refactoring. Spec wise, change seems ok, as instrumentation can have specific error handling.
| // met, not a failure of the request, and should not be recorded as a span | ||
| // error. Other 3xx status codes (e.g. a 301 signaling a misconfigured | ||
| // bucket region) can indicate a real problem and are still recorded. | ||
| func isNotModifiedResponseError(err error) bool { |
There was a problem hiding this comment.
I think this is packing two independent questions
- Can status code be extracted from the error (Does a response exist)
- Is that status code the one of interest (304)
Keeping it as functional is useful for testing, would recommend something like this
func responseStatusCode(err error) (code int, ok bool) {
var respErr *smithyhttp.ResponseError
if !errors.As(err, &respErr) {
return 0, false
}
return respErr.HTTPStatusCode(), true
}
func isNotModifiedStatus(err error) bool {
code, ok := responseStatusCode(err)
return ok && code == http.StatusNotModified
}|
|
||
| ### Fixed | ||
|
|
||
| - Don't mark spans as errors in `go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws` when the AWS SDK returns an error wrapping an HTTP `304 Not Modified` response, such as from a conditional S3 `GetObject` request whose precondition (e.g. `IfModifiedSince`) was not satisfied. |
There was a problem hiding this comment.
Need to be moved to bottom. Also please attach the PR number.
|
Split |
ps-mir
left a comment
There was a problem hiding this comment.
Test for responseStatusCode can be dropped as its covered by tests of calling function. Rest looks ok.
| assert.NotContains(t, input.Header[key], value) | ||
| } | ||
|
|
||
| func Test_responseStatusCode(t *testing.T) { |
There was a problem hiding this comment.
This can dropped as Test_isNotModifiedStatus provides equivalent coverage for responseStatusCode.
Motivation: otelaws marks a span as an error and sets error.type whenever the AWS SDK returns a non-nil error for an API call, including HTTP 304 Not Modified responses. A 304 is returned by services that support conditional requests (e.g. S3 GetObject with IfModifiedSince) when the precondition is not satisfied, which is expected client behavior, not a failure. The span already carries http.response.status_code, so marking it as an error adds noise without new information. Approach: Add isNotModifiedResponseError, which unwraps the returned error with errors.As into a *smithyhttp.ResponseError and checks whether its HTTP status code is 304. initializeMiddlewareAfter now skips setting error.type and span status Error only for this specific case; the error returned to the caller is unchanged. Other 3xx codes (e.g. a 301 from a misconfigured bucket region) are intentionally left recorded as errors, since those can indicate a real problem. Validation: go test ./... in instrumentation/github.com/aws/aws-sdk-go-v2/otelaws, including a new table-driven case that reproduces the issue: a route53 call returning HTTP 304 no longer sets span status Error or error.type, while a sibling case for HTTP 301 confirms other redirects are still recorded as errors. Also ran golangci-lint run --allow-serial-runners, go vet ./..., and gofmt -l . (clean) in the same package. Report: open-telemetry#6331 Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
Covers the branch where errors.As fails to match a *smithyhttp.ResponseError, which the existing table-driven integration test never exercised, per codecov/patch feedback on patch coverage. Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
Split isNotModifiedResponseError into responseStatusCode (extracts the HTTP status code from a wrapped smithyhttp.ResponseError) and isNotModifiedStatus (checks for 304), per review, and move the CHANGELOG entry to the bottom of the Fixed section with the PR number attached. Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
Test_isNotModifiedStatus already exercises responseStatusCode's nil, non-response, and response-error branches, per review. Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
ec9210c to
d35c6de
Compare
Motivation:
otelaws marks a span as an error and sets error.type whenever the AWS
SDK returns a non-nil error for an API call, including HTTP 304 Not
Modified responses. A 304 is returned by services that support
conditional requests (e.g. S3 GetObject with IfModifiedSince) when the
precondition is not satisfied, which is expected client behavior, not
a failure. The span already carries http.response.status_code, so
marking it as an error adds noise without new information.
Approach:
Add isNotModifiedResponseError, which unwraps the returned error with
errors.As into a *smithyhttp.ResponseError and checks whether its
HTTP status code is 304. initializeMiddlewareAfter now skips setting
error.type and span status Error only for this specific case; the
error returned to the caller is unchanged. Other 3xx codes (e.g. a 301
from a misconfigured bucket region) are intentionally left recorded
as errors, since those can indicate a real problem.
Validation:
go test ./... in
instrumentation/github.com/aws/aws-sdk-go-v2/otelaws, including a new
table-driven case that reproduces the issue: a route53 call returning
HTTP 304 no longer sets span status Error or error.type, while a
sibling case for HTTP 301 confirms other redirects are still recorded
as errors. Also ran golangci-lint run --allow-serial-runners, go vet
./..., and gofmt -l . (clean) in the same package.
Report: #6331
Signed-off-by: Pujitha Paladugu 10557236+pujitha24@users.noreply.github.com
Fixes #6331